// DataViews.h : Declaration of the CDataViews

#pragma once
#include "resource.h"       // main symbols

#include "ArtFramework.h"
#include "_IDataViewsEvents_CP.h"


#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif


class CDataViewEntrust
{
public:
	CDataViewEntrust()
	{
	}

	~CDataViewEntrust()
	{
	}

	int CmpICollectionName(LPCTSTR lpszName)	//***
	{
		CComBSTR	strText;
		CWindow		wnd;

		m_pDataView->GetWnd(&wnd.m_hWnd);
		wnd.GetWindowText(&strText);

		return StrCmpI(strText, lpszName);
	}

	IDataView* GetDataView()
	{
		return m_pDataView;
	}

	void SetDataView(IDataView *pDataView)
	{
		m_pDataView = pDataView;
	}

	STDMETHOD(QueryInterface)(REFIID iid, void** ppObject)
	{
		return m_pDataView->QueryInterface(iid, ppObject);
	}

protected:
	IDataView *m_pDataView;

private:
};


// CDataViews
namespace _DataViewsCol
{
	typedef CDataViewEntrust	_ClassItem;
	typedef IDataView		_Interface;

	typedef std::list<_ClassItem*> _ColType;
	typedef saf::_CopyClassToInterface<_ClassItem, _Interface> _CopyVariantLong;
	typedef CComEnumOnSTL<IEnumUnknown, &IID_IEnumUnknown, IUnknown*, _CopyVariantLong, _ColType> _EnumType;

	typedef saf::ICollectionOnVariantSTLImpl<IDataViews, _ColType, _Interface, _CopyVariantLong, _EnumType> _ICollection;
};

class ATL_NO_VTABLE CDataViews :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CDataViews, &CLSID_DataViews>,
	public ISupportErrorInfo,
	public IConnectionPointContainerImpl<CDataViews>,
	public CProxy_IDataViewsEvents<CDataViews>,
	public IDispatchImpl<_DataViewsCol::_ICollection, &IID_IDataViews, &LIBID_ArtFrameLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
	CDataViews()
	{
	}

DECLARE_REGISTRY_RESOURCEID(IDR_DATAVIEWS)


BEGIN_COM_MAP(CDataViews)
	COM_INTERFACE_ENTRY(IDataViews)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
	COM_INTERFACE_ENTRY(IConnectionPointContainer)
END_COM_MAP()

BEGIN_CONNECTION_POINT_MAP(CDataViews)
	CONNECTION_POINT_ENTRY(__uuidof(_IDataViewsEvents))
END_CONNECTION_POINT_MAP()
// ISupportsErrorInfo
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);


	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

public:
	STDMETHOD(UpdateState)();
	STDMETHOD(UpdateEnable)();
	STDMETHOD(UpdateData)();
	STDMETHOD(WriteData)();
	STDMETHOD(ReadData)();
	STDMETHOD(get_DataObject)(ULONG_PTR** ppDataObject);
	STDMETHOD(put_DataObject)(ULONG_PTR* pDataObject);
	STDMETHOD(Add)(IDataView* pDataView);
	STDMETHOD(Move)(IDataView* pDataView);

protected:

	ULONG_PTR *m_pDataObject;

	//CAtlList<CUpdateView
};

OBJECT_ENTRY_AUTO(__uuidof(DataViews), CDataViews)
